package lessons.no4.no48;

/*
 * 第4.8 垃圾回收
 */
public class No4_8 {
    public static void main(String[] args) {
        free1();
        System.out.println("#####################");
        //free2();
    }

    static public void free1()
    {
        Test t = new Test("对象1");
        t = null;
        for(int i=0;i<10;i++)
        {
            
            Test t1 = new Test("对象"+i);
            t1 = null;
            
            System.out.println("free1 .. "+i+" ..");
        }
    }

    static public void free2()
    {
        Test t = new Test("对象2");
        t = null;
        System.gc();
        //Runtime.getRuntime().gc();
        for(int i=0;i<10;i++)
        {
            t = new Test("对象2");
            t = null;
            System.gc();
            System.out.println("free2 .. "+i+" ..");
        }
    }
}

class Test
{
    private String mName;
    //private int[] mdata = new int[10000000];
    public Test(String name)
    {
        mName = name;
    }

    @Override
    protected void finalize() throws Throwable {
        // TODO Auto-generated method stub
        System.out.println(""+mName+" 对象被回收 ... ");
        //super.finalize();
    }
}